//
//  XHSelectDataTypeCell.m
//  xidian
//
//  Created by 冷山 on 16/5/18.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHSelectDataTypeCell.h"

#import "HMSegmentedControl.h"

#define SCREEN_WIDTH                    ([UIScreen mainScreen].bounds.size.width)

@interface XHSelectDataTypeCell()
@property (weak, nonatomic) HMSegmentedControl *segmentedControl;
@end

@implementation XHSelectDataTypeCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)HMSegmentedControl:(NSArray*)array
{
    [self.segmentedControl removeFromSuperview];
    HMSegmentedControl *segmentedControl1 = [[HMSegmentedControl alloc] initWithSectionTitles:array];
    segmentedControl1.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
    segmentedControl1.backgroundColor=[UIColor clearColor];
    segmentedControl1.frame = CGRectMake(0, 5, SCREEN_WIDTH, 40);
    segmentedControl1.segmentEdgeInset = UIEdgeInsetsMake(0, 20, 0, 20);
    segmentedControl1.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
    segmentedControl1.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    segmentedControl1.selectionIndicatorColor=[ColorManager colorWithHexString:@"#1B95EA" alpha:1];
    segmentedControl1.selectionIndicatorHeight=3;
    segmentedControl1.verticalDividerEnabled = NO;
    //    segmentedControl1.verticalDividerColor = [UIColo/r colorWithWhite:0 alpha:0.3];
    //    segmentedControl1.verticalDividerWidth = 0.5f;
    [segmentedControl1 setTitleFormatter:^NSAttributedString *(HMSegmentedControl *segmentedControl, NSString *title, NSUInteger index, BOOL selected) {
        NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName : [ColorManager colorWithHexString:@"#000000" alpha:0.6],NSFontAttributeName : [UIFont systemFontOfSize:14]}];
        if (selected) {
            attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName : [ColorManager colorWithHexString:@"#1B95EA" alpha:1],NSFontAttributeName : [UIFont systemFontOfSize:14]}];
        }
        return attString;
    }];
    [segmentedControl1 addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
    [self addSubview:segmentedControl1];
    self.segmentedControl=segmentedControl1;
    [self.segmentedControl setSelectedSegmentIndex:0];
}

- (void)segmentedControlChangedValue:(HMSegmentedControl *)segmentedControl
{
    NSLog(@"Selected index %ld (via UIControlEventValueChanged)", (long)segmentedControl.selectedSegmentIndex);
    [_delegate selectItem:(long)segmentedControl.selectedSegmentIndex];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
